package com.situ.team5.kzq.power.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.team5.kzq.power.service.QxService;
import com.situ.team5.kzq.recruit.dao.SalaryGrantDetailsDAO;
import com.situ.team5.kzq.recruit.service.SalaryGrantDetailsService;
import com.situ.team5.pojo.ConfigMajor;
import com.situ.team5.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
public class QxController {


    @Autowired
    SalaryGrantDetailsService sservice;
    @Autowired
    QxService qxser;

    @RequestMapping("user_list")
    public String user_list(Map map,
                            @RequestParam(defaultValue = "1", required = false) Integer startPage,
                            @RequestParam(defaultValue = "5", required = false) Integer PageSize) {
        PageHelper.startPage(startPage, PageSize); //使用分页插件
        List<Map> ucm = qxser.User_config_majorSelectAll();
        PageInfo pageInfo = new PageInfo(ucm, 5); //保存分页信息
        map.put("pageInfo", pageInfo);
        map.put("ucm", ucm);
        System.out.println(ucm + "你好");
        return "/page/power/user_list.html";
    }

    //页面跳转添加
    @RequestMapping("user_add")
    public String user_add(Map map) {
        System.out.println("职位表");
        //职位表的全查
        List<Map> configMajor = qxser.config_majorSelectALL();
        System.out.println("职位表"+configMajor);
        map.put("configMajor", configMajor);
        return "/page/power/user_add.html";
    }
    //添加到数据库
    @RequestMapping("user_add2")
    public String user_add2(Users u) {
        qxser.users_Insert(u);
        return "redirect:user_list";
    }



    //修改
    @RequestMapping("user_list_update")
    public String user_list_update( Map map,int id){
        //职位表的全查
        List<Map> configMajor = qxser.config_majorSelectALL();
        System.out.println("职位表"+configMajor);
        Map map1 = qxser.users_Update(id);
        map.put("map1", map1);
        map.put("configMajor", configMajor);
return"/page/power/user_edit.html";
    }
    //真的修改
    @RequestMapping("user_update2")
    public String user_update2(Users s){
           qxser.user_update2(s);
        return "redirect:user_list";
    }


    @RequestMapping("user_list_delete")
    public String user_list_delete(int id){
        qxser.users_Delete(id);
        return "redirect:user_list";

    }

}
